/*
 * @features: 功能
 * @description: 说明
 * @Date: 2021-04-04 21:11:41
 * @Author: judu233(769471424@qq.com)
 * @LastEditTime: 2021-09-19 21:38:06
 * @LastEditors: judu233
 */
interface ICom {
    init?(): void;
}
class Com<T> {
    com: T;
    nodeData: any;
    constructor(com: T, nodeData: any) {
        this.com = com;
        this.nodeData = nodeData;
        this.init();
    }

    init() { }
}

export class ComMgr {
    private static _instence: ComMgr;
    public static get ins() {
        if (this._instence == null)
            this._instence = new ComMgr();
        return ComMgr._instence;
    }

    getComFun(name: string, nodeData: any): Com<any> {
        let comFun = this[name];
        if (comFun)
            return comFun(nodeData);
        else
            console.warn(`未声明相应组件初始化函数,名字：${name}`);
    }

    [`cc.Sprite`](nodeData: any) {
        return new class Spirte extends Com<cc.Sprite> implements ICom {
            init() {

            }
        }(new cc.Sprite(), nodeData);
    }

    [`cc.Label`](nodeData: any) {
        return new class Label extends Com<cc.Label> implements ICom {

        }(new cc.Label(), nodeData);
    }
}